package cn.wei.sdd.core.service.impl;

import cn.wei.sdd.core.pojo.entity.UserAccount;
import cn.wei.sdd.core.mapper.UserAccountMapper;
import cn.wei.sdd.core.pojo.vo.UserAccountVO;
import cn.wei.sdd.core.service.UserAccountService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

/**
 * <p>
 * 用户账户 服务实现类
 * </p>
 *
 * @author Wei
 * @since 2021-09-22
 */
@Service
public class UserAccountServiceImpl extends ServiceImpl<UserAccountMapper, UserAccount> implements UserAccountService {

    @Override
    public UserAccountVO getMyAccount(Long userId, Long userType) {
        QueryWrapper<UserAccount> userAccountQueryWrapper = new QueryWrapper<>();
        userAccountQueryWrapper.eq("user_id",userId).eq("user_type",userType);
        UserAccount userAccount = baseMapper.selectOne(userAccountQueryWrapper);

        UserAccountVO userAccountVO = new UserAccountVO();
        userAccountVO.setAmount(userAccount.getAmount());
        userAccountVO.setFreezeAmount(userAccount.getFreezeAmount());
        userAccountVO.setTotalShoyi(userAccount.getTotalShouyi());
        userAccountVO.setTotalTixian(userAccount.getTotalTixian());
        return userAccountVO;
    }

    @Override
    public BigDecimal getAmountByUidAndUType(Long userId, Integer userType) {
        QueryWrapper<UserAccount> userAccountQueryWrapper = new QueryWrapper<>();
        userAccountQueryWrapper.eq("user_id",userId).eq("user_type",userType);
        UserAccount userAccount = baseMapper.selectOne(userAccountQueryWrapper);
        return userAccount.getAmount();
    }
}
